var activedTree = 165;

function getClassName(b,c,a)
{
            if(b==undefined)
            {
                b=""
            }
            if(c==1)
            {
                return"tree_item"
            }
            if(c==2)
            {
                if(b.lastIndexOf("GRAY")!=-1&&a!="now")
                {
                   return"tree_title_gray"
                }
               else
                {
                    if(b.lastIndexOf("GRAY")!=-1&&a=="now")
                    {
                     return"tree_title_now"
                    }
                    else
                    {
                        if(b.lastIndexOf("GRAY")!=-1)
                         {
                            return"tree_title_gray"
                         }
                         else
                         {
                           if(a=="none")
                            {
                              return"tree_title"
                            }
                            else
                            {
                               if(a=="open")
                               {
                                 return"tree_title_open"
                                }
                               else
                                {
                                   if(a=="close")
                                   {
                                    return"tree_title_close"
                                   }
                                   else
                                   {
                                        if(a=="now")
                                        {
                                          return"tree_title_now"
                                        }
                                   }
                                 }
                              }
                          }
                 }
             }
        }
            if(c==3)
             {
                return"tree_list"
             }
             
            if(c==4)
            {
                if(a=="now"&&b.indexOf("GRAY")!=-1)
                 {
                   return"tree_list_now_gray"
                 }
                else
               {
                     if(a=="now")
                     {
                       return"tree_list_now"
                     }
                    else
                    {
                        if(b.indexOf("GRAY")!=-1)
                        {
                            return"tree_list_gray"
                        }
                        else
                        {
                            return"tree_list"
                        }
                    }
               }
            }
}


function getStyleIcon(b,a)
{
        if(b.indexOf("ICON_NEW")!=-1)
        {
            a+='<img class="tree_icon" src="http://img.china.alibaba.com/images/myalibaba/icon/target_new.gif">';
            return a
        }
        if(b.indexOf("ICON_NO")!=-1)
        {
            a+='<img class="tree_icon" src="http://img.china.alibaba.com/images/myalibaba/icon/target_no.gif">';
            return a
        }
        if(b.indexOf("ICON_HOT")!=-1)
        {
         a+='<img class="tree_icon" src="http://img.china.alibaba.com/images/myalibaba/icon/target_hot.gif">';
         return a
        }
        if(b.indexOf("ICON_FREE")!=-1)
        {
            a+='<img class="tree_icon" src="http://img.china.alibaba.com/images/myalibaba/icon/target_free.gif">';
            return a
        }
        if(b.indexOf("ICON_TRUST")!=-1)
        {
            a+='<img class="tree_icon" src="http://img.china.alibaba.com/images/myalibaba/icon/target_cxt.gif">';
        return a
        }
    return a
}




function initTreeHTML()
{
    if(document.getElementById("tree1")&&(typeof menuJson)=="object"&&document.getElementById("leftmenu"))
    {
        var l=document.getElementById("leftmenu");
        
        var b=document.getElementById("tree1");
        var q=b.innerHTML;
        b.innerHTML="";
        var p;
        if(menuJson.childMenu==undefined)
        {
            p=menuJson[0]["childMenu"]
        }
        else
        {
            p=menuJson.childMenu
        }
        var m=true;
        var o=false;
        for(var e=0;e<p.length;e++)
        {
            var c=document.createElement("div");
            c.treeId=p[e].id;
            c.className=getClassName(p[e].style,1,"none");
            var h=document.createElement("div");
            if(p[e]["childMenu"].length==0)
            {
                if(p[e].url!="")
                {
                    if(p[e].style.indexOf("TARGET_BLANK")!=-1)
                    {
                        h.innerHTML=getStyleIcon(p[e].style,'<a target="_blank" href="'+p[e].url+'">'+p[e].name+"</a>")
                    }
                    else
                    {
                        h.innerHTML=getStyleIcon(p[e].style,'<a target="_self" href="'+p[e].url+'">'+p[e].name+"</a>")
                    }
                }
                else
                {
                    if(p[e].style.indexOf("TARGET_BLANK")!=-1)
                    {
                        h.innerHTML=getStyleIcon(p[e].style,'<a target="_blank" >'+p[e].name+"</a>")
                    }
                    else
                    {
                        h.innerHTML=getStyleIcon(p[e].style,'<a target="_self" >'+p[e].name+"</a>")
                    }
                }
                h.treeId=p[e].id;
                if(p[e].id==activedTree)
                {
                    h.id=getClassName(p[e].style,2,"now")
                }
                else
                {
                    h.className=getClassName(p[e].style,2,"none")
                }
                c.appendChild(h)
            }
            else
            {
                if(p[e]["childMenu"].length>0)
                {
                    h.innerHTML=getStyleIcon(p[e].style,'<a target="_blank" >'+p[e].name+"</a>");
                    h.treeId=p[e].id;
                    if((typeof activedTree)=="undefined"&&m)
                    {
                        h.className=getClassName(p[e].style,2,"open");
                        if(menuJson[0]["name"].indexOf("\u9996\u9875")!=-1)
                        {
                            m=true;o=true
                        }
                        else
                        {
                            m=false;o=true
                        }
                    }
                    else
                    {
                        if(p[e].id==activedTree)
                        {
                            h.className=getClassName(p[e].style,2,"open");
                            o=true
                        }
                        else
                        {
                            h.className=getClassName(p[e].style,2,"close")
                        }
                    }
                    c.appendChild(h);
                    var a=p[e]["childMenu"];
                    var j=document.createElement("ul");
                    j.className=getClassName(p[e].style,3,"none");
                    if(o)
                    {
                        j.style.display="block";
                        o=false
                    }
                    else
                    {
                        if((typeof activedTree)=="undefined"&&o)
                        {
                            j.style.display="block";
                            if(menuJson[0]["name"].indexOf("\u9996\u9875")!=-1)
                            {
                                o=true
                            }
                            else
                            {
                                o=false
                            }
                        }
                        else
                        {
                            j.style.display="none"
                        }
                    }
                (
                        function()
                            {
                        var i=p[e].style;
                        var k=j;
                        h.onclick=function()
                        {
                            if(this.className==getClassName(i,2,"close"))
                            {
                                k.style.display="block";
                                this.className=getClassName(i,2,"open")
                            }
                            else
                            {
                                this.className=getClassName(i,2,"close");
                                k.style.display="none"
                            }
                            l.style.height="";
                            if(l.offsetHeight<559)
                            {
                                l.style.height="559px"
                            }
                            initTreeHeight()
                            }
                        }
                    )();
                    for(var d=0;d<a.length;d++)
                    {
                        var n=document.createElement("li");
                        var g;
                        if(a[d].style.indexOf("TARGET_BLANK")!=-1)
                        {
                            if(a[d].url=="")
                            {
                                g="<a >"+a[d].name+"</a>"
                            }
                            else
                            {
                                g='<a target="_blank" href="'+a[d].url+'">'+a[d].name+"</a>"
                            }
                        }
                        else
                        {
                            if(a[d].url=="")
                            {
                                g="<a >"+a[d].name+"</a>"
                            }
                            else
                            {
                                g='<a target="_self" href="'+a[d].url+'">'+a[d].name+"</a>"
                            }
                        }
                        n.innerHTML=getStyleIcon(a[d].style,g);
                        n.treeId=a[d].id;
                        n.className=getClassName(a[d].style,4,"none");
                        j.appendChild(n);
                        if(a[d].id==activedTree)
                        {
                            j.style.display="block";
                            n.id=getClassName(a[d].style,4,"now");
                            h.className=getClassName(p[e].style,2,"open")
                        }
                        }
                    c.appendChild(j)
                    }
                }
            b.appendChild(c)
            }
        if((typeof serviceCenterHtml)!="undefined"&&serviceCenterHtml!="")
        {
            var f=document.createElement("div");
            f.innerHTML=serviceCenterHtml;
            b.appendChild(f)
        }
        }
    }
    
    
function initTreeHeight()
{
    if(document.getElementById("new-content")&&document.getElementById("leftmenu"))
    {
        var a=document.getElementById("new-content").offsetHeight;
        var b=document.getElementById("leftmenu").offsetHeight;
        if(b<a&&a>400)
        {
            document.getElementById("leftmenu").style.height=a+"px"
        }
        else
        {
          if(b<400&&a<400)
          {
              document.getElementById("leftmenu").style.height=400+"px"
          }
          else
          {
           document.getElementById("leftmenu").style.height=b+"px"
          } 
       }
    }
    if(document.getElementById("login-content"))
    {
        var c=document.getElementById("login-content").offsetHeight;if(c<400)
        {
            document.getElementById("login-content").style.height=400+"px"
        }
    }
}


